package com.hanock.sm.fork2d;

import android.util.Log;


public class Scene extends Node {
	
	private static final int WIDTH_DEFAULT = 500;
	private static final int HEIGHT_DEFAULT = 500;
	
	private boolean dirty;
	private boolean started;
	private boolean drawed;
	private int touchDenyRemain;

	public Scene() {
		setSize(WIDTH_DEFAULT, HEIGHT_DEFAULT);
		setAnchor(0, 0);
		setPosition(0, 0);
	}
	
	@Override
	public void progress(int elapsed) {
		super.progress(elapsed);
		
		if (touchDenyRemain > 0)
			touchDenyRemain -= elapsed;
		
		if (!started){
			started = true;
			onStart();
		}
	}
	
	@Override
	public boolean visit(float x, float y, TouchMode mode) {
		
		if (isTouchDenied())
			return true;
		
		return super.visit(x, y, mode);
	}
	
	@Override
	public void visit(Canvas canvas) {
		if (!drawed){
			onBeforeFirstDraw();
			drawed = true;
		}
		
		super.visit(canvas);
	}
	
	public void onStart(){
		Log.i("test2", "onStart: " + getClass().getName());
	}
	
	public void onBeforeFirstDraw(){
		Log.i("test2", "onBeforeFirstDraw: " + getClass().getName());
	}
	
	public void onBackPressed(){
		
	}
	
	public void onMenu(int code){
		
	}
	
	public void onActivityPause(){
		
	}
	
	public void onActivityResume(){
		
	}
	
	public void refresh(){
		
	}
	
	public void denyTouch(int time){
		if (touchDenyRemain < time)
			touchDenyRemain = time;
	}
	
	public boolean isDirty() {
		return dirty;
	}
	
	public void setDirty(boolean dirty) {
		this.dirty = dirty;
	}
	
	public boolean isTouchDenied(){
		return touchDenyRemain > 0;
	}
}
